//
//  AdAction.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/18.
//

import Foundation
import HandyJSON
import Moya
import ReSwift
import ReSwiftThunk

enum HTEnumAdAction: Action {
    case htEnumAdConfig(var_adConfig: HTAdConfig?)
    case htEnumSetShowPremiumGuideStatus(var_showPremiumGuideStatus: String)

    // 获取广告配置信息
    static func ht_adConfig() -> Thunk<HTAppState> {
        Thunk<HTAppState> { dispatch, _ in
            HTNetworkManager().ht_request(.htEnumAdConfig) { result in
                let var_data = result.ht_data()
                let var_adConfig = HTAdConfig.deserialize(from: var_data)!

                HTCoreDataManager().ht_addAdConfig(adConfig: var_adConfig)
                dispatch(HTEnumAdAction.htEnumAdConfig(var_adConfig: var_adConfig))
            }
        }
    }

    static func ht_setShowPremiumGuideStatus(showPremiumGuideStatus: String) -> Thunk<HTAppState> {
        Thunk<HTAppState> { dispatch, _ in
            dispatch(HTEnumAdAction.htEnumSetShowPremiumGuideStatus(var_showPremiumGuideStatus: showPremiumGuideStatus))
        }
    }
}
